﻿using DongFangGuoKai.WMS.IApiService.ElectronicTags;
using DongFangGuoKai.WMSPlatform.Core;
using DongFangGuoKai.WMSPlatform.Domain.HZJLYModel;
using DongFangGuoKai.WMSPlatform.Domain.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;

namespace DongFangGuoKai.WMSPlatform.WebApi.Controllers.ElectronicTags
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ElectronicTagsController : ApiBaseController
    {
        private readonly IElectronicTSpreadWallsagsService electronicTSpreadWallsags;
        private readonly Repository<SpreadWalls> spreadwallsrepost;

        public ElectronicTagsController(IElectronicTSpreadWallsagsService electronicTSpreadWallsags,
            Repository<SpreadWalls> spreadwallsrepost)
        {
            this.electronicTSpreadWallsags = electronicTSpreadWallsags;
            this.spreadwallsrepost = spreadwallsrepost;
        }
        /// <summary>
        /// 通知分播墙亮灭灯
        /// </summary>
        /// <param name="successTagRequest"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult ShowTag(SuccessTagRequest successTagRequest)
        {

            var res = electronicTSpreadWallsags.successTagResults(successTagRequest, spreadwallsrepost, out string message);
            if (res)
            {
                return Success(message);
            }
            return Failed(message);
            
        }

        /// <summary>
        /// 通知分播墙亮灭灯循环调用
        /// </summary>
        /// <param name="successTagRequest"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ShowTagFor(int count,string seqNum,int showColor,string nWall)
        {
            string message = string.Empty;
            for (int i = 1; i <= count; i++)
            {
                SuccessTagRequest successTagRequest = new SuccessTagRequest()
                {
                    nWall = nWall,
                    seqNum = seqNum,
                    tagList = new List<Tag>()
                    {
                        new Tag() 
                        { 
                            showColor = showColor , 
                            showData =showColor == 5 ? "0" : i.ToString(), 
                            tagIndex = i.ToString()
                        }
                    }
                };

                var res = electronicTSpreadWallsags.successTagResults(successTagRequest, spreadwallsrepost, out message);
                if (!res)
                {
                    return Failed(message);
                }

            }
            return Success(message);
        }


        /// <summary>
        /// 分播墙熄灯
        /// </summary>
        /// <param name="tagList"></param>
        /// <returns></returns>
        [HttpPost]
        public SuccessTagResults RequestExtinguish(Extinguished tagList)
        {
            return  electronicTSpreadWallsags.RequestExtinguish(tagList,spreadwallsrepost);
        }
    }
}
